<?php

namespace backend\controllers;

use backend\models\Basemodule;
use backend\models\Baseprivilege;
use Yii;

class ModuleController extends CommonController
{
    /**
     * @param \yii\base\Action $action
     * @return bool
     * @throws \yii\web\BadRequestHttpException
     */
    public function beforeAction($action)
    {
        if (parent::beforeAction($action)) {
            if ($this->roleId > 2 && $this->roleId < 10){
                return false;
            }
            return true;
        } else {
            return false;
        }
    }

    public function actionIndex()
    {
        return $this->renderPartial('index');
    }


    public function actionGetNode()
    {
        $node = new Basemodule();
        $data = $node->getNode($this->roleId);
        return $this->renderJson($data);
    }


    public function actionGetModule()
    {
        $id = yii::$app->request->get('id');
        $module = new Basemodule();
        $data = $module->getModule($id);
        return $this->renderJson($data);
    }


    public function actionGroupModule()
    {
        $post = yii::$app->request->post();
        $rid = $post['rid'];
        $gid = $post['gid'];
        $primodel = new Baseprivilege();
        $data = $primodel->getNode($rid);
        return $this->renderJson($data);
    }


    public function actionModifyModule()
    {
        $post = yii::$app->request->post();
        $privilege = new Baseprivilege();
        $result = $privilege->savePrivilege($post);
        return $this->renderJson($result);
    }


    public function actionUpdateModule()
    {
        $post = yii::$app->request->post();
        $module = new Basemodule();
        $result = $module->updateModule($post);
        return $this->renderJson($result);
    }


    public function actionHandlerModule()
    {
        $post = yii::$app->request->post();
        $module = new Basemodule();
        $result = $module->delModule($post);
        return $this->renderJson($result);
    }

}
